// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_PROD_WIP_MTRL_CUR
// * CreateDate    : 2014-02-18 18:04:07
// * Creater       : CodeSmith
// * LastChangeDate: 2014-02-18 18:04:07
// * LastChanger   : 2014-02-18 18:04:07
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Prod
{
/// <summary>
    /// ProdWipMtrlCur
    /// </summary>
    public partial class ProdWipMtrlCurBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objProdWipMtrlCurEntity">Entity</param>
        /// <returns>Entity</returns>
        public static ProdWipMtrlCurEntity GetProdWipMtrlCur(ProdWipMtrlCurEntity objProdWipMtrlCurEntity)
        {
            return DataAccess.SelectSingle<ProdWipMtrlCurEntity>(objProdWipMtrlCurEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objProdWipMtrlCurEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertProdWipMtrlCur(ProdWipMtrlCurEntity objProdWipMtrlCurEntity)
        {
            return DataAccess.Insert(objProdWipMtrlCurEntity);
        }

        public static bool InsertProdWipMtrlCur(List<ProdWipMtrlCurEntity> objProdWipMtrlCurEntityList)
        {
            return DataAccess.Insert(objProdWipMtrlCurEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objProdWipMtrlCurEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateProdWipMtrlCur(ProdWipMtrlCurEntity objProdWipMtrlCurEntity)
        {
            return DataAccess.Update(objProdWipMtrlCurEntity);
        }

        public static bool UpdateProdWipMtrlCur(List<ProdWipMtrlCurEntity> objProdWipMtrlCurEntityList)
        {
            return DataAccess.Update<ProdWipMtrlCurEntity>(objProdWipMtrlCurEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objProdWipMtrlCurEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteProdWipMtrlCur(ProdWipMtrlCurEntity objProdWipMtrlCurEntity)
        {
            return DataAccess.Delete(objProdWipMtrlCurEntity);
        }

        public static bool DeleteProdWipMtrlCur(List<ProdWipMtrlCurEntity> objProdWipMtrlCurEntityList)
        {
            return DataAccess.Delete<ProdWipMtrlCurEntity>(objProdWipMtrlCurEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetProdWipMtrlCurAll()
        {
            return DataAccess.SelectAllDataSet<ProdWipMtrlCurEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<ProdWipMtrlCurEntity> GetProdWipMtrlCurAllList()
        {
            return DataAccess.SelectAll<ProdWipMtrlCurEntity>();
        }
        #endregion


        public static List<ProdWipMtrlCurEntity> GetProdWipMtrlCurByCondition(ProdWipMtrlCurEntity objProdWipMtrlCurEntity)
        {
            List<ProdWipMtrlCurEntity> wipMtrls = new List<ProdWipMtrlCurEntity>();
            if (objProdWipMtrlCurEntity == null)
                return DataAccess.SelectAll<ProdWipMtrlCurEntity>();
            else
            {
                string strCondition = "";
                  ProdWipMtrlCurEntity condition = new ProdWipMtrlCurEntity();
                  if (!string.IsNullOrEmpty(objProdWipMtrlCurEntity.WoNo))
                  {
                      strCondition = " and wip.Wo_No like'%" + objProdWipMtrlCurEntity.WoNo + "%'";
                  }
                  if (!string.IsNullOrEmpty(objProdWipMtrlCurEntity.MtrlStatus))
                  {
                      strCondition = " and wip.Mtrl_Status ='" + objProdWipMtrlCurEntity.MtrlStatus + "'";
                  }

                  if (string.IsNullOrEmpty(strCondition))
                      return DataAccess.Select<ProdWipMtrlCurEntity>(condition);
                  else
                  {
                      string sql = "select * from Prod_Wip_Mtrl_Cur wip where 1=1 "+ strCondition;
                    
                      DataSet ds = DataAccess.SelectDataSet(sql);
                      if (ds != null && ds.Tables.Count > 0)
                      {
                         
                          foreach (DataRow row in ds.Tables[0].Rows)
                          {
                              wipMtrls.Add(new ProdWipMtrlCurEntity(row));
                          }
                          return wipMtrls;
                      }
                      else
                          return wipMtrls;
                  }
            }
        }

        public static DataSet  GetProdWipMtrlCurDsByCondition(ProdWipMtrlCurEntity objProdWipMtrlCurEntity)
        {
           
            if (objProdWipMtrlCurEntity == null)
                return DataAccess.SelectAllDataSet<ProdWipMtrlCurEntity>();
            else
            {
                string strCondition = "";
                ProdWipMtrlCurEntity condition = new ProdWipMtrlCurEntity();
                if (!string.IsNullOrEmpty(objProdWipMtrlCurEntity.WoNo))
                    strCondition = " and wipMtrl.Wo_No like'%" + objProdWipMtrlCurEntity.WoNo + "%'";

                string sql = "select wipMtrl.*,p.Product_Id Mtrl_Id from Prod_Wip_Mtrl_Cur wipMtrl left join mst_product p on wipMtrl.Mtrl_Code=p.Product_Code where 1=1 ";
                if(!string.IsNullOrEmpty(strCondition)) sql+= strCondition;
                DataSet ds = DataAccess.SelectDataSet(sql);
                return ds;
            }
        }
        
	}
	
	
}	

